<template>
  <PageContainer title="文章分类">
    <template #add
      ><el-button @click="onemitchannel()" type="primary"
        >添加分类</el-button
      ></template
    >
    <el-table v-loading="loading" :data="tableData" style="width: 100%">
      <el-table-column type="index" label="序号" width="200"></el-table-column>
      <el-table-column prop="channelname" label="分类名称"></el-table-column>
      <el-table-column
        prop="channelothername"
        label="分类别名"
      ></el-table-column>
      <el-table-column prop="address" label="操作">
        <template #default="{ row, $index }">
          <el-button
            :icon="Edit"
            circle
            plain
            type="primary"
            @click="onemitchannel(row, $index)"
          ></el-button>
          <el-button
            :icon="Delete"
            circle
            plain
            type="danger"
            @click="ondeletechannel(row, $index)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-empty v-show="isempty" description="description" />
    <ArticleDialog ref="dialog" :gettableData="gettableData"></ArticleDialog>
  </PageContainer>
</template>

<script setup>
import { Edit, Delete } from '@element-plus/icons-vue'
import ArticleDialog from './components/ArticleEdit.vue'
import { reactive, ref } from 'vue'
import {
  articlechannelservice,
  articledeletechannelservice
} from '@/api/article.js'

let isempty = ref(false)
let loading = ref(false)
let tableData = ref()
const dialog = ref()
const gettableData = async () => {
  loading.value = true
  const res = await articlechannelservice()
  loading.value = false
  tableData.value = reactive(res.data.channeldata)
  if (!tableData.value) {
    isempty.value = true
  }
}
gettableData()
const onemitchannel = (row, $index) => {
  dialog.value.open(row, $index)
}

const ondeletechannel = async (row, $index) => {
  await ElMessageBox.confirm('你确定要删除该分类吗', '温馨提示', {
    type: 'warning',
    confirmButtonText: '确认',
    cancelButtonText: '取消'
  })
  await articledeletechannelservice($index)
  ElMessage.success('删除成功')
  gettableData()
}
</script>

<style scoped lang="less">
::v-deep .el-table__row {
  height: 0.3808rem;
  line-height: 0.3808rem;
}
</style>
